<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录页面</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/login.css">
    <script type="text/javascript" src="js/jquery.min.js"></script>
</head>

<body>
    <div class="container-login">
        <div class="container-pic">
            <img src="pic/封面2.png" alt="登录图片">
        </div>
        <div class="login-dialog">
            <h3>登录到系统</h3>
            <form onsubmit="return false;">
                <div class="row">
                    <label for="userName">用户名</label>
                    <input type="text" id="userName" placeholder="请输入用户名" class="form-control">
                </div>
                <div class="row">
                    <label for="password">密码</label>
                    <input type="password" id="password" placeholder="请输入密码" class="form-control">
                </div>
                <div class="row">
                    <button type="button" onclick="login()">登录</button>
                </div>

                <div class="row">
                    <button type="button" onclick="register()">注册账号</button>
                </div>
            </form>
        </div>
    </div>
    <script>
        function login() {
            $.ajax({
                type: "post",
                url: "/user/login",
                data: {
                    name: $("#userName").val(),
                    password: $("#password").val()
                },
                success: function (result) {
                    if (result && result.data !== false) {
                        location.href = "book_list.html?currentPage=1";
                    } else {
                        alert("账号或密码错误");
                    }
                }
            });
        }
        function register() {
            location.href = "register.html";
        }
    </script>
</body>

</html>